package com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.agency.chlid

import android.os.Bundle
import android.util.Log
import android.view.View
import com.alibaba.fastjson.JSON
import com.example.library_common.base.BaseDataBindingFragment
import com.example.library_common.base.BaseFragmentEx
import com.example.shushiyunsst.R
import com.example.shushiyunsst.databinding.FragmentAgencyHeaderBinding
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.agency.bean.AgencyProxyIndexBean
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.agency.bean.AgencyProxyIndexImageListBean
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.provider.NewSaleBannerAdapter
import com.example.shushiyunsst.util.HiDataBus
import com.youth.banner.Banner
import com.youth.banner.indicator.CircleIndicator
import java.util.ArrayList

/**
 * 代理header轮播图
 * */
class AgencyHeaderFragment : BaseDataBindingFragment<FragmentAgencyHeaderBinding>() {


    companion object {
        fun newInstance(): AgencyHeaderFragment {
            val args = Bundle()
            val fragment = AgencyHeaderFragment()
            fragment.arguments = args
            return fragment
        }
    }


    private var mBannerAdapter: AgencyHeaderBannerAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport = false
    }

    override fun layoutId(): Int {
        return R.layout.fragment_agency_header
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mBannerAdapter = AgencyHeaderBannerAdapter(ArrayList(), _mActivity)
        viewBinder.mBanner.adapter = mBannerAdapter

        viewBinder.mBanner.indicator = CircleIndicator(_mActivity)
        viewBinder.mBanner.addBannerLifecycleObserver(this)

        val proxyIndex=_mActivity.getString(R.string.proxyIndex)

        HiDataBus.with<AgencyProxyIndexBean>(proxyIndex)
            .observerSticky(this, true, {
                mBannerAdapter?.addAll(it.imageList)
        })

    }


}